package com.example.tests;

import java.io.File;
import java.io.FileReader;
import java.util.Properties;
import java.util.Random;
import java.util.logging.Logger;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import com.example.fw.ApplicationManager;


public class TestBase {
	
	protected static ApplicationManager app;
	protected Logger log =Logger.getLogger("TEST");

	@BeforeTest
	public void setUp() throws Exception {
		log.info("SetUp start");
		String configFile = System.getProperty("configFile", "application.properties");
		Properties properties = new Properties();
		properties.load(new FileReader(new File(configFile)));
		app = ApplicationManager.getInstance(properties);
		//app = new ApplicationManager(properties);
		log.info("SetUp end");
	  }

	@AfterTest
	public void tearDown() throws Exception {
		log.info("tearDown start");
		//app.stop();
		ApplicationManager.getInstance(null).stop();
		log.info("tearDown end");
	  }
	
	public static String generateRandomString(){
		Random rnd = new Random();
		String rndString = new String();
		if (rnd.nextInt(3)==0){
			return  "";
		} else{
		char[] text = new char[4];
		for (int i = 0; i < 4; i++){
			text[i] = (char)(97+ rnd.nextInt(25));
 			rndString = rndString + text[i];
		}
		return rndString + rnd.nextInt();
		}
	}

	public static int getRandomIndex(int listSize) {
		Random rnd = new Random();
	    int index = rnd.nextInt(listSize-1);
	    return index;
	}
}
